﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using LDSP.BRL;

namespace LDSP.Util
{
    public class FavoriteCodificationExport : CodificationExportBase<R_EnterpriseCatalog, R_EnterpriseCodification>
    {
        private int _enterpriseId;

        public FavoriteCodificationExport(int enterpriseID)
        {
            _enterpriseId = enterpriseID;
        }

        protected override void InitialRows(DataTable dt, IList<R_EnterpriseCodification> codifications)
        {
            foreach (R_EnterpriseCodification cod in codifications)
            {
                dt.Rows.Add(cod.Priority.ToString(),
                    cod.Codification.Category.Name,
                    cod.Codification.Name,
                    cod.Codification.Organization,
                    cod.Codification.ReferenceNumber,
                    cod.Codification.ReleaseDT,
                    cod.Codification.ImplementDT,
                    GenerateInvalidList(cod.Codification),
                    cod.Principal,
                    cod.Name,
                    cod.KeyItems,
                    cod.Action,
                    "",//No need data here, just for export because the limitation of the template.
                    cod.SelfEvaluation);
            }
        }

        protected override void InitialColumns(DataTable dt)
        {
            dt.Columns.Add("Priority");
            dt.Columns.Add("Category");
            dt.Columns.Add("Title");
            dt.Columns.Add("Agency");
            dt.Columns.Add("OrderNumber");
            dt.Columns.Add("IssueDate");
            dt.Columns.Add("EffectiveDate");
            dt.Columns.Add("Invalidate");
            dt.Columns.Add("Principal");
            dt.Columns.Add("Summary");
            dt.Columns.Add("KeyPoints");
            dt.Columns.Add("ImplementationSteps");
            dt.Columns.Add("CurrentAnalysis");
            dt.Columns.Add("SelfEvaluation");
        }

        protected override IList<R_EnterpriseCatalog> GetAllCatalogs()
        {
            return new R_EnterpriseCatalog().GetListByEnterpriseID(_enterpriseId); ;
        }

        protected override void GenerateList(IDictionary<string, DataTable> dataTables, R_EnterpriseCatalog cata)
        {
            IList<R_EnterpriseCodification> codifications = new R_EnterpriseCodification().GetList(_enterpriseId, cata.CatalogID);

            string codName = GetFullName(cata.Catalog);
            dataTables.Add(codName, ConstructDT(codifications));
        }
    }
}
